<template>
	<view class="container">
		<view class="address-list">
			<view class="a-address" v-for="(item,index) in addressList" :key="index">
				<view class="left-text" :class="item.isDefault? 'active':''" @tap="selectTap(item.id)">
					<view class="name-tel">
						{{item.name}} {{item.tel}}
					</view>
					<view class="address-box">
						{{item.address}}
					</view>
					<view class="address-box">
						{{item.home}}
					</view>
				</view>
				<view class="right-edit" @tap="editAddess(item.id)"></view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="add-btn" @tap="addAddess">新增收货地址</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: []
			}
		},
		onShow() {
			/*获取用户保存的地址信息*/
			this.getAddressList()
		},
		methods: {
			async getAddressList() {
				const result = await this.$myRequest({
					url: '/api/address/query'
				})
				this.addressList  = result 
			},
			selectTap(id) {
				console.log("tap item id:" + JSON.stringify(id));
			},
			editAddess(id) {
				console.log("edit item id:" + id);
			},
			addAddess() {
				/*跳转到添加新地址页面*/
				uni.navigateTo({
					url: '/pages/address/address'
				})
			}
		}
	}
</script>

<style>
	.container {
		background-color: #F2f2f2;
	}

	.address-list {
		width: 100%;
		background-color: #fff;
		margin-top: 20upx;
		padding-bottom: 100upx;
	}

	.address-list .a-address {
		width: 720upx;
		margin-left: 30upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30upx 0;
		border-bottom: 1upx solid #eee;
	}

	.a-address .left-text {
		width: 610upx;
		box-sizing: border-box;
		padding-left: 58upx;
	}

	.a-address .left-text.active {
		background: url() no-repeat left center;
		background-size: 28upx auto;
	}

	.a-address .left-text .name-tel {
		margin-bottom: 20upx;
	}

	.a-address .left-text .address-box {
		font-size: 24upx;
		color: #888888;
		line-height: 36upx;
	}

	.a-address .right-edit {
		width: 109upx;
		height: 100%;
		padding: 50upx 0 50upx 58upx;
		box-sizing: border-box;
		background: url() no-repeat 43upx center;
		background-size: 35upx auto;
	}
	
	.bottom-box {
		position: fixed;
		width: 100%;
		bottom: 0;
		font-size: 28upx;
		color: #000000;
		border-top: 1upx solid #eee;
		height: 100upx;
		line-height: 100upx;
		background: #fff url() no-repeat 705upx center;
		background-size: 15upx auto;
	}

	.bottom-box .add-btn {
		margin-left: 30upx;
		padding-left: 70upx;
		background: url() no-repeat left center;
		background-size: 40upx auto;
	}
</style>

